<?php

namespace api\modules\v1\controllers\statistics;

use Yii;
use api\controllers\OnAuthController;
use common\helpers\CommonHelper;
use common\models\clinic\Doctor;
use common\models\statistics\StatisticsDoctor;
use services\statistics\StatisticsDoctorService;

/**
 * Class DoctorController
 * @package api\modules\v1\controllers\statistics
 */
class DoctorController extends OnAuthController
{
    /**
     * @var Doctor
     */
    public $modelClass = Doctor::class;


    /**
     * @api {get} /v1/statistics/doctor/list 医生报表列表
     * @apiName list
     * @apiGroup ClinicDoctor
     *
     * @apiParam {Number} project_id                    项目ID
     * @apiParam {Number} type                          类型【1日期、2上旬(1-10)、3中旬(1-20)、4全月】
     * @apiParam {String} start_time                    开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                      结束时间【格式：2020-01-01】
     * @apiParam {String} sort_column                   排序字段
     * @apiParam {Number} sort_type                     排序值【1正序、2倒序，sort_column存在有效】
     * @apiParam {Number} page                          页码
     * @apiParam {Number} pageSize                      每页显示数量
     *
     * @apiSuccess {Object}  data                       返回数据
     * @apiSuccess {Number}  data.page                  当前页码
     * @apiSuccess {Number}  data.pageSize              每页显示数
     * @apiSuccess {Number}  data.total                 总数
     * @apiSuccess {Array}   data.list                  诊室列表
     * @apiSuccess {Number}  data.list.id               医生ID
     * @apiSuccess {Number}  data.list.project_id       项目ID
     * @apiSuccess {Number}  data.list.clinic_id        诊室ID
     * @apiSuccess {String}  data.list.name             诊室名称
     * @apiSuccess {String}  data.list.clinic_name      诊室名
     * @apiSuccess {Number}  data.list.status           状态
     * @apiSuccess {String}  data.list.status_str       状态值
     */
    public function actionList()
    {
        $params = Yii::$app->request->get();

        $params['type'] = $params['type'] ?? StatisticsDoctor::TYPE_DAY;
        $params['start_time'] = $params['start_time'] ?? date('Y-m-d');
        $params['end_time'] = $params['end_time'] ?? date('Y-m-d');
        $params['sort_column'] = $params['sort_column'] ?? '';
        $params['sort_type'] = $params['sort_type'] ?? 1;

        $page = $params['page'] ?? 0;
        $pageSize = $params['pageSize'] ?? 0;

        // 查询结果
        $statisticsService = new StatisticsDoctorService();
        return $statisticsService->getListPage($params, (int)$page, (int)$pageSize);
    }
}
